import collections
class Solution(object):
    def getFolderNames(self, names):
        f = set()
        d = collections.defaultdict(lambda: 1)
        ans = []
        for name in names:
            if name not in f:
                ans.append(name)
                f.add(name)
            else:
                while name + '(' + str(d[name]) + ')' in f:
                    d[name] += 1
                ans.append(name + '(' + str(d[name]) + ')')
                f.add(name + '(' + str(d[name]) + ')')
                d[name] += 1
        return ans
